package com.vineetmanohar.nitrogen;

import java.io.File;

/**
 * Represents the type of source from which the model is loaded, e.g. xml, json,
 * yaml
 * 
 * @author vineetmanohar
 */
public enum ModelSourceType {
	JSON(".json"), XML(".xml");

	private String suffix;

	private ModelSourceType(String suffix) {
		this.suffix = suffix;
	}

	public static ModelSourceType createFromFile(File modelFile) {
		return createFromFileName(modelFile.getName());
	}

	private static ModelSourceType createFromFileName(String name) {
		for (ModelSourceType modelSourceType : values()) {
			if (name.endsWith(modelSourceType.suffix)) {
				return modelSourceType;
			}
		}

		return null;
	}
}